package com.example.jsf.controller;

import com.example.jsf.Repository.InvestmentRepository;
import com.example.jsf.entity.Income;
import com.example.jsf.entity.Investment;
import com.example.jsf.entity.Member;
import com.example.jsf.other.DataHelper;
import com.example.jsf.other.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("investment")
public class InvestmentController {

    @Autowired
    private InvestmentRepository investmentRepository;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @PostMapping("addInvestment")
    public Result addInvestment(@RequestBody Investment investment) {
        investment.setCreateTime(new Date());
        System.out.println(investment);
        return  Result.success(investmentRepository.save(investment));
    }

    @GetMapping("getInvestment")
    public Result getInvestment(@RequestParam("pageNo") int pageNo,@RequestParam(value = "pageSize",defaultValue = "2") int pageSize,String goodName,String addressTypeName) {
        String s = DataHelper.selectSQL(Investment.class);
        s+=" order by create_time desc";
        System.out.println("s = " + s);
        return Result.success(DataHelper.pageQuery(jdbcTemplate,s,pageNo,pageSize, Investment.class));
    }
}
